package com.passionfruit.web.www;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.passionfruit.common.utils.PageUtils;
import com.passionfruit.common.utils.Query;
import com.passionfruit.common.utils.R;
import com.passionfruit.module.entity.BlogArticle;
import com.passionfruit.module.service.IBlogArticleService;
import com.xiaoleilu.hutool.util.CollectionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 
 * 
 * @author weirdor
 * @email 179946422@qq.com
 * @date 2017-11-06 20:05:15
 */
@RestController
@RequestMapping("/module/blogarticle")
public class BlogArticleController {
	@Autowired
	private IBlogArticleService blogArticleService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		List<BlogArticle> sysLogList = blogArticleService.queryList(query);
		EntityWrapper<BlogArticle> wrapper = new EntityWrapper<BlogArticle>();
		int total = blogArticleService.selectCount(wrapper);

		PageUtils pageUtil = new PageUtils(sysLogList, total, query.getLimit(), query.getPage());
		return R.ok().put("page", pageUtil);
	}
	

	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	public R info(@PathVariable("id") Integer id){
		BlogArticle blogArticle = blogArticleService.queryObject(id);

		return R.ok().put("blogArticle", blogArticle);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody BlogArticle blogArticle){
		blogArticleService.save(blogArticle);
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody BlogArticle blogArticle){
		blogArticleService.update(blogArticle);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody Integer[] ids){
		blogArticleService.deleteBatchIds(CollectionUtil.newArrayList(ids));
		
		return R.ok();
	}
	
}
